<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PropertyPage.php 367 2010-02-06 20:04:08Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalPageRecord');
class PropertyPage extends PortalSystemPage
{
	private $_pagename		= '';
	private $_controlname	= '';
	private $_portletname	= '';
	private $_recid			= 0;
	private	$_pagerecord	= null;

	public function onInit($param)
	{
		parent::onInit($param);

		if(!$this->User)
		{
			$this->reportError(1,Prado::localize("You need to be logged in to use this page"));
		}

		if($this->User->RoleId != $this->Application->Parameters['AdminRole'])
		{
			$this->reportError(1,Prado::localize("You need to be logged in to use this page"));
		}
	}

	public function getPageRecord()
	{
		if($this->_pagerecord === null)
		{
			$this->_pagerecord = PortalPageRecord::finder()->findByfullpath($this->Request['pagename']);
		}

		return $this->_pagerecord;
	}

	public function onLoad($param)
	{
		$this->Title = $this->Application->Parameters['SiteTitle'] . " - " . Prado::localize("Page properties");

		if(!$this->IsPostBack)
		{
			$this->PageLayout->DataSource 		= PortalUtil::getAvailablePortalLayouts();
			$this->PageLayout->SelectedValue	= $this->PageRecord->layoutname;
			$this->PageLayout->dataBind();

			$this->Active->Checked				= TPropertyValue::ensureBoolean($this->PageRecord->active);
			$this->DisplayName->Text			= $this->PageRecord->displayname;
			$this->CancelLink->NavigateUrl		= $this->Service->constructUrl($this->pid->Value,array("PageMode" => $this->Page->EditMode));
		}
	}

	public function saveButtonClicked($sender,$param)
	{
		if($this->Page->IsValid)
		{
			$this->PageRecord->active			= TPropertyValue::ensureInteger($this->Active->Checked);
			$this->PageRecord->displayname		= $this->DisplayName->Text;
			$this->PageRecord->layoutname		= $this->PageLayout->getSelectedValue();
			$this->PageRecord->metakeywords		= $this->tbMetaKeywords->Text;
			$this->PageRecord->metadescription	= $this->tbMetaDescription->Text;
			$this->PageRecord->expire			= 0;
			$this->PageRecord->save();
			$this->gotoPage($this->PageRecord->fullpath,array("PageMode" => $this->Page->EditMode));
		}
	}

	public function cancelButtonClicked($sender,$param)
	{
		$this->gotoPage($this->PageRecord->fullpath,array("PageMode" => $this->Page->EditMode));
	}
}
?>